package com.yuan.controller.admin;


import com.yuan.pojo.entity.IntegralGrade;
import com.yuan.result.R;
import com.yuan.service.IntegralGradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 积分等级表 前端控制器
 * </p>
 *
 * @author yuan
 * @since 2021-11-08
 */

@Api(tags = "积分等级管理")
//@CrossOrigin
@RestController
@RequestMapping("/admin/core/integralGrade")
public class AdminIntegralGradeController {
    @Resource
    private IntegralGradeService integralGradeService;

    @ApiOperation("积分等级列表")
    @GetMapping("/list")
    public R listAll(){
        List<IntegralGrade> list = integralGradeService.list();
        return R.success().data("list",list).message("获取列表成功");
    }

    @ApiOperation(value = "根据id删除数据记录",notes = "逻辑删除数据记录")
    @DeleteMapping("/remove/{id}")
    public R removeById(@PathVariable Long id){
        boolean result = integralGradeService.removeById(id);
        if (result){
            return R.success().message("删除成功");
        }
        else {
            return R.success().message("删除失败");
        }
    }

    @ApiOperation("新增积分等级")
    @PostMapping("/save")
    public R save(@RequestBody IntegralGrade integralGrade){
        boolean result = integralGradeService.save(integralGrade);
        if (result){
            return R.success().message("新增数据成功");
        }else {
            return R.error().message("新增数据失败");
        }
    }

    @ApiOperation("根据id查询积分等级")
    @GetMapping ("/get/{id}")
    public R getById(@PathVariable Long id){
        IntegralGrade result = integralGradeService.getById(id);
        if (result != null){
            return R.success().data("list",result).message("查询数据成功");
        }else {
            return R.error().message("查询数据失败");
        }
    }

    @ApiOperation("根据id更新积分等级")
    @PutMapping("/update")
    public R updateById(@RequestBody IntegralGrade integralGrade){
        boolean result = integralGradeService.updateById(integralGrade);
        if (result){
            return R.success().message("更新数据成功");
        }else {
            return R.error().message("更新数据失败");
        }
    }
}

